{
  "cells": [
    {
      "cell_type": "markdown",
      "id": "7b502c12",
      "metadata": {
        "id": "7b502c12"
      },
      "source": [
        "# Phi-4 Conversational Chat"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "6f550ca9",
      "metadata": {
        "id": "6f550ca9"
      },
      "source": [
        "**Description:**\n",
        "\n",
        "Basic conversational inference with Phi-4 demonstrating chat-style turn-based communication."
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DhivyaBharathy-web/PraisonAI/blob/main/examples/cookbooks/Phi_4_Conversational.ipynb)\n"
      ],
      "metadata": {
        "id": "CB4mkM7yPmua"
      },
      "id": "CB4mkM7yPmua"
    },
    {
      "cell_type": "markdown",
      "id": "e0db4638",
      "metadata": {
        "id": "e0db4638"
      },
      "source": [
        "**Dependencies**\n",
        "\n",
        "```python\n",
        "!pip install transformers accelerate\n",
        "!pip install torch\n",
        "```"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "25ef05dd",
      "metadata": {
        "id": "25ef05dd"
      },
      "source": [
        "**Tools Used**\n",
        "\n",
        "- HuggingFace Transformers\n",
        "- PyTorch"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "8986b9d8",
      "metadata": {
        "id": "8986b9d8"
      },
      "source": [
        "**YAML Prompt**\n",
        "\n",
        "```yaml\n",
        "system: You are a tutor.\n",
        "user: Teach me what machine learning is.\n",
        "```"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "ffdb2319",
      "metadata": {
        "id": "ffdb2319"
      },
      "outputs": [],
      "source": [
        "from transformers import AutoTokenizer, AutoModelForCausalLM\n",
        "\n",
        "tokenizer = AutoTokenizer.from_pretrained(\"microsoft/phi-4\")\n",
        "model = AutoModelForCausalLM.from_pretrained(\"microsoft/phi-4\")\n",
        "\n",
        "prompt = \"Teach me what machine learning is.\"\n",
        "inputs = tokenizer(prompt, return_tensors=\"pt\")\n",
        "outputs = model.generate(**inputs, max_new_tokens=80)\n",
        "print(tokenizer.decode(outputs[0], skip_special_tokens=True))"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "ac4caeac",
      "metadata": {
        "id": "ac4caeac"
      },
      "source": [
        "**Output**\n",
        "\n",
        "Explains machine learning in a clear, tutor-like manner.\n",
        "\n",
        "Machine learning is a field of artificial intelligence that allows computers to learn from data without being explicitly programmed.\n",
        "It involves training algorithms on large datasets so they can recognize patterns, make decisions, or perform tasks.\n",
        "There are different types of machine learning, including supervised, unsupervised, and reinforcement learning.\n",
        "For example, in supervised learning, a model is trained using labeled data to predict outcomes.\n",
        "Overall, machine learning is widely used in applications like recommendation systems, image recognition, and natural language processing.\n"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}